package com.example.campus_activity_backend.controller;

import com.example.campus_activity_backend.common.BaseResponse;
import com.example.campus_activity_backend.common.ErrorCode;
import com.example.campus_activity_backend.common.ResultUtil;
import com.example.campus_activity_backend.domain.Course;
import com.example.campus_activity_backend.exception.BusinessException;
import com.example.campus_activity_backend.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/course")
@RestController
public class CourseController {
    @Autowired
    private CourseService courseService;

    @PostMapping("/add")
    public BaseResponse<Long> addCourse(@RequestBody Course course){
        if(course == null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        long id = courseService.addCourse(course);
        return ResultUtil.success(id);
    }
}
